const {
  userCollection
} = require('../../common/constants')
const {
  ERROR
} = require('../../common/error')

/**
 * 获取账户信息
 * 
 */
module.exports = async function () {
  const {
    uid
  } = this.authInfo
  const getUserRes = await userCollection.doc(uid).get()
  const userRecord = getUserRes && getUserRes.data && getUserRes.data[0]
  if (!userRecord) {
    throw {
      errCode: ERROR.ACCOUNT_NOT_EXISTS
    }
  }
  return {
    errCode: 0,
    data: userRecord
  }
}
